<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}知疑 - 社区问答论坛{% endblock %}</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- 自定义样式 -->
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    {% block styles %}{% endblock %}
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary sticky-top">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('main.index') }}">
                <i class="fas fa-question-circle"></i> 知疑
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                    <li class="nav-item">
                        <a class="nav-link {% if request.endpoint == 'main.index' %}active{% endif %}" href="{{ url_for('main.index') }}">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.endpoint == 'question.create' %}active{% endif %}" href="{{ url_for('question.create') }}">提问</a>
                    </li>
                </ul>
                
                <!-- 搜索表单 -->
                <form class="d-flex me-2" method="get" action="{{ url_for('main.search') }}">
                    {{ search_form and search_form.query(class="form-control me-2", placeholder="搜索问题...") }}
                    <button class="btn btn-light" type="submit">
                        <i class="fas fa-search"></i>
                    </button>
                </form>
                
                <!-- 用户相关菜单 -->
                <div class="navbar-nav">
                    {% if current_user.is_authenticated %}
                    <ul class="navbar-nav">
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                <img src="{{ url_for('static', filename='img/' + current_user.avatar) }}" class="avatar-sm me-1" alt="{{ current_user.username }}">
                                {{ current_user.username }}
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
                                <li>
                                    <a class="dropdown-item" href="{{ url_for('user.profile', username=current_user.username) }}">
                                        <i class="fas fa-user me-2"></i>个人主页
                                    </a>
                                </li>
                                <li>
                                    <a class="dropdown-item" href="{{ url_for('user.edit_profile') }}">
                                        <i class="fas fa-cog me-2"></i>编辑资料
                                    </a>
                                </li>
                                <li><hr class="dropdown-divider"></li>
                                <li>
                                    <a class="dropdown-item" href="{{ url_for('auth.logout') }}">
                                        <i class="fas fa-sign-out-alt me-2"></i>退出登录
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                    {% else %}
                    <ul class="navbar-nav">
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('auth.login') }}">登录</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('auth.register') }}">注册</a>
                        </li>
                    </ul>
                    {% endif %}
                </div>
            </div>
        </div>
    </nav>

    <!-- 闪现消息 -->
    {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
            <div class="container mt-3">
                {% for category, message in messages %}
                    <div class="alert alert-{{ category }} alert-dismissible fade show">
                        <i class="fas {% if category == 'success' %}fa-check-circle{% elif category == 'danger' %}fa-exclamation-circle{% else %}fa-info-circle{% endif %} me-2"></i>
                        {{ message }}
                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                    </div>
                {% endfor %}
            </div>
        {% endif %}
    {% endwith %}

    <!-- 主要内容区域 -->
    <main class="py-4 flex-grow-1">
        <div class="container">
            {% block content %}{% endblock %}
        </div>
    </main>

    <!-- 页脚 -->
    <footer class="footer py-3 bg-light mt-auto">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <p class="mb-0 text-muted">&copy; {{ now('Y') }} 知疑问答社区</p>
                </div>
                <div class="col-md-6 text-end">
                    <p class="mb-0 text-muted">Powered by Flask & Bootstrap</p>
                </div>
            </div>
        </div>
    </footer>

    <!-- JavaScript -->
    <!-- Bootstrap JS Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    {% block scripts %}{% endblock %}
</body>
</html> 